package com.hongtu.supplychain.finance.config;


import com.hongtu.supplychain.finance.interceptor.AuthInterceptor;
import com.hongtu.supplychain.finance.interceptor.MAuthInterceptor;
import com.hongtu.supplychain.finance.interceptor.ResponseInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 拦截器配置
 *
 * @author chaiy
 * @create 2017-04-11 15:28
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter {
    final Logger logger = LoggerFactory.getLogger(InterceptorConfig.class);

    @Bean
    public ResponseInterceptor responseInterceptor() {
        return new ResponseInterceptor();
    }

    @Bean
    public AuthInterceptor authInterceptor() {
        return new AuthInterceptor();
    }

    @Bean
    public MAuthInterceptor mAuthInterceptor (){
        return new MAuthInterceptor();
    }

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(responseInterceptor()).addPathPatterns("/**");
        logger.info("responseInterceptor加载完成");
        registry.addInterceptor(authInterceptor()).addPathPatterns("/hongtu/**");
        logger.info("authInterceptor加载完成");
        registry.addInterceptor(mAuthInterceptor()).addPathPatterns("/hongtu/**");
        logger.info("MAuthIntercepter加载完成");
    }
}
